﻿<template>
  <a-modal
    title="编辑VIP用户信息"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="自定义编号" prop="Code">
          <a-input v-model="entity.Code" autocomplete="off" placeholder="自定义编号" disabled="true" />
        </a-form-model-item>
        <a-form-model-item label="用户OpenId" prop="WxCode">
          <a-input v-model="entity.OpenId" autocomplete="off" placeholder="登录成功后返回的code" disabled="true" />
        </a-form-model-item>
        <a-form-model-item label="姓名" prop="Name">
          <a-input v-model="entity.Name" autocomplete="off" placeholder="姓名" disabled="true" />
        </a-form-model-item>
        <a-form-model-item label="性别" prop="Sex">
          <a-input v-model="entity.Sex" autocomplete="off" placeholder="男/女" disabled="true" />
        </a-form-model-item>
        <a-form-model-item label="出生日期" prop="Birth">
          <a-input v-model="entity.Birth" autocomplete="off" placeholder="出生日期" disabled="true" />
        </a-form-model-item>
        <a-form-model-item label="电话" prop="Phone">
          <a-input v-model="entity.Phone" autocomplete="off" placeholder="电话" disabled="true" />
        </a-form-model-item>
        <a-form-model-item label="地址" prop="Address">
          <a-input v-model="entity.Address" autocomplete="off" placeholder="地址" disabled="true" />
        </a-form-model-item>
        <a-form-model-item label="邮箱" prop="Email">
          <a-input v-model="entity.Email" autocomplete="off" placeholder="邮箱" disabled="true" />
        </a-form-model-item>
        <a-form-model-item label="所属公司" prop="Company">
          <a-input v-model="entity.Company" autocomplete="off" placeholder="所属公司" disabled="true" />
        </a-form-model-item>
        <a-form-model-item label="头像地址" prop="Icon">
          <a-input v-model="entity.Icon" autocomplete="off" placeholder="头像地址" disabled="true" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data () {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    init () {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm (id, title) {
      this.init()

      if (id) {
        this.loading = true
        this.$http.post('/Base_VIPUser/Base_VIPUserInfo/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit () {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/Base_VIPUser/Base_VIPUserInfo/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
